package com.lz.football.module.compete.item
{
	import com.common.utils.Reflection;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.FriendEvent;
	import com.liangzhong.model.compete.vo.InlandRankVo;
	import com.liangzhong.model.friend.vo.FriendInfoVo;
	import com.lz.football.module.base.IComponent;
	
	import common.BaseView.IItemMouseEvent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class InlandRankItem extends Sprite implements IComponent,IItemMouseEvent
	{
		/**
		 * 
		 */
		private var _skin:MovieClip;
		/**
		 *排名  
		 */
		private var sort:TextField;
		/**
		 *名称  
		 */
		private var playerName:TextField;
		/**
		 *挑战点 
		 */
		private var rival:TextField;
		/**
		 *等级 
		 */
		private var Lv:TextField;
		/**
		 *vip 
		 */
		private var vip:TextField;
		/**
		 *效果 
		 */
		private var frame:MovieClip;
		private var _vo:InlandRankVo;
		
		public function InlandRankItem()
		{
			super();
		}
		/**
		 * type 1 为上轮比赛结果 
		 * 2为当前的比赛结果  
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			var type:int = view as int;
			if(type == 1)
			{
				_skin = Reflection.createInstance("com.football.compete.upRoundRank");//上轮比赛item
				
				rival = _skin.rival;
			}else
			{
				_skin = Reflection.createInstance("com.football.compete.currentRoundRank");
				Lv = _skin.Lv;
				vip = _skin.vip
			}
			sort = _skin.sort;
			playerName = _skin.playerName;
			
			frame = _skin.frame;
			this.addChild(_skin);
			if(frame.parent)frame.parent.removeChild(frame);
			addEvtListener();
		}
		/**
		 *设置上轮排名  
		 * 
		 */
		public function setUpData($vo:InlandRankVo):void
		{
			//B9D2FC
			_vo = $vo;
			sort.textColor = 0xB9D2FC;
			playerName.textColor = 0xB9D2FC;
			rival.textColor = 0xB9D2FC;
			sort.text = $vo.sort + "";
			if($vo.sort ==1)
			{
				sort.text = "国王";//FF0000
				sort.textColor = 0xFF0000;
				playerName.textColor = 0xFF0000;
				rival.textColor = 0xFF0000;
			}
			if($vo.sort == 2|| $vo.sort == 3 || $vo.sort == 4)
			{
				sort.text = "大将";//FFCC00
				sort.textColor = 0xFFCC00;
				playerName.textColor = 0xFFCC00;
				rival.textColor = 0xFFCC00;
			}
			
			playerName.text = $vo.clubname;
			rival.text = $vo.rival + "";
		}
		
		/**
		 *设置当前排名 
		 * 
		 */
		public function setCurrentData($vo:InlandRankVo):void
		{
			_vo = $vo;
			playerName.text = $vo.clubname;
			sort.text = $vo.sort + "";
			Lv.text = $vo.level + "";
//			vip.text = "";
//			if($vo.VIP > 0)
//				vip.text = "Vip"+ $vo.VIP;
			vip.text = ""+ $vo.rival;
		}
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.CLICK,onMouseClick);
			this.addEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
		}
		
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,onMouseClick);
			this.removeEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.removeEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
		}
		
		public function destroyView():void
		{
			removeEvtListener();
		}
		/**
		 * 移出
		 * @param event
		 * 
		 */
		public function onMouseRollOut(event:MouseEvent):void
		{
			if(frame.parent)frame.parent.removeChild(frame);
		}
		/**
		 * 移上
		 * @param event
		 * 
		 */
		public function onMouseRollOver(event:MouseEvent):void
		{
			this.addChild(frame);
		}
		/**
		 *单击 
		 * @param event
		 * 
		 */
		public function onMouseClick(event:MouseEvent):void
		{
			var vo:FriendInfoVo = new FriendInfoVo();
			vo.friendid = _vo.clubid;
			AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.LOOK_UP_FRIEND,{vo:vo,type:1}));
		}
		
		public function get tips():Object
		{
			return null;
		}
		/**
		 * 
		 * @param value
		 * 
		 */
		public function set tips(value:Object):void
		{
			
		}
	}
}